package com.eliza.base.views.component.navigationDrawer

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.launch


@Preview
@Composable
private fun asdad() {

    ModalNavigationDrawerX.Show(navController = rememberNavController())
}

object ModalNavigationDrawerX {
    @Composable
    fun Show(navController: NavController) {
        var statex by remember {
            mutableIntStateOf(0)
        }
        Column {
            Button(onClick = {
                statex = (statex.plus(1)) % 2
            }) {
                Text(text = "click to change$statex")
            }
            when (statex) {
                0 -> Simple(true)
                1 -> Simple(false)
            }
        }
    }

    @Composable
    private fun Simple(gesturesEnabled: Boolean) {
        val drawerState = rememberDrawerState(DrawerValue.Closed)
        val scope = rememberCoroutineScope()
        ModalNavigationDrawer(
            scrimColor = Color.Cyan,
            drawerState = drawerState,
            gesturesEnabled = gesturesEnabled, // 拖拽打开
            drawerContent = {
                Column {
                    Text(text = "drawerContent->")
                    Button(
                        modifier = Modifier.padding(top = 16.dp),
                        onClick = { scope.launch { drawerState.close() } },
                        content = { Text("rememberCoroutineScope 关闭") }
                    )
                }
            },
            content = {
                Column(
                    modifier = Modifier.padding(10.dp),
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    Text(text = if (drawerState.isClosed) ">>>>>>>>> content" else "<<<<<<<<< content")
                    Spacer(Modifier.height(20.dp))
                    Button(onClick = { scope.launch { drawerState.open() } }) {
                        Text("打开")
                    }
                }
            }
        )
    }


}
